//
//  DidiPaiViewController.m
//  嘀嘀拍
//
//  Created by wangjia_01 on 16/2/25.
//  Copyright © 2016年 wangjia_01. All rights reserved.
//

#import "DidiPaiViewController.h"
//倒入地图类库
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
#import "BBScrollImageView.h"
#import "MoreThanVedioViewController.h"
#import "HomeCollectionCell.h"
#import "HeaderView.h"
#import "FooterReusableView.h"
#import "CustomButton.h"
#import "MoreThanDetailViewController.h"
//百度地图
#import "BMKMapManager.h"
#import "BMKMapView.h"
#import "BMKPointAnnotation.h"
#import "BMKOverlayView.h"
#import "BMKGroundOverlay.h"
#import "BMKGroundOverlayView.h"
#import "BMKPinAnnotationView.h"
#import "BMKCircle.h"
#import "BMKCircleView.h"
#import "BMKLocationService.h"
static NSString *staticCell=@"HomeCollectionCell";
@interface DidiPaiViewController ()<CLLocationManagerDelegate,MKMapViewDelegate,UIGestureRecognizerDelegate,UIScrollViewDelegate,
UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,
BBScrollImageViewDataSource,BBScrollImageViewDelegate,BMKMapViewDelegate,BMKLocationServiceDelegate>

{
    UIScrollView * _topScrollView;//创建顶部的ScrollView
    CLLocationManager * _locationManager;//定位管理类
    MKMapView * _mapView;//地图视图
    NSMutableArray *urls;
    
    BMKMapView * _baidumapView ;//百度地图
    BMKLocationService * _baiduLocation;//百度地图定位
    
}
@property (weak, nonatomic) IBOutlet UIView *bannerView;
@property (weak, nonatomic) IBOutlet UIScrollView *MainScrollView;
@property (weak, nonatomic) IBOutlet UIView *hearNavBar;

@property (retain,nonatomic)BBScrollImageView *scrollImageView;
//广告图片的数组
@property (retain,nonatomic)NSMutableArray *bannerArray;



@property (weak, nonatomic) IBOutlet NSLayoutConstraint *mCollectionHC;
@property (weak, nonatomic) IBOutlet UICollectionView *mCollection;

@property (weak, nonatomic) IBOutlet UISegmentedControl *segment;
@property (nonatomic,strong)NSMutableArray *dataArray;
@end

@implementation DidiPaiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //取消自动布局
   // self.automaticallyAdjustsScrollViewInsets = NO;
    

    [self customNavigation];
    _dataArray=@[].mutableCopy;
    _bannerArray=@[].mutableCopy;
    
    _mCollection.delegate=self;
    _mCollection.dataSource=self;
    [_mCollection registerNib:[UINib nibWithNibName:@"HomeCollectionCell" bundle:nil] forCellWithReuseIdentifier:staticCell];
    
    
    [_mCollection registerNib:[UINib nibWithNibName:@"HeaderView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView"];
    
    [_mCollection registerNib:[UINib nibWithNibName:@"FooterReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"FooterReusableView"];
    
    
    //第一次进入页面先加载广场视图
    //[self creatTopScrollerView];
    //[self creatInfoView];
    [self getImageArray];
    [self getDataSource];
    
    // Do any additional setup after loading the view.
}

- (void)getDataSource
{
    WC;
    [httpRequest getHomeVideoComplement:^(NSDictionary *dic) {
         DLog(@"%@",dic);
        if ([dic[@"code"] integerValue]==200) {
           
            CGFloat height=0;
            NSArray *array=dic[@"data"];
            if (array.count>0) {
                for (int i=0; i<array.count; i++) {
                    [weakSelf.dataArray addObject:array[i]];
                    height+=74;//头部高度 尾部高度 +间隙高度
                    NSArray *subArray=array[i][@"recommend_video"];
                    if ( ![subArray isEqual:[NSNull null]]) {
                        NSInteger columns;
                        
                        
                        if (subArray.count%2>0 ) {
                            
                            columns=(subArray.count/2)+1;

                        }else
                        {
                            columns=subArray.count/2;
                            
                        }
                        
                       
                        height+=columns*120;
                        }
                    
                }
                 weakSelf.mCollectionHC.constant=height+71;
            }else
            {
            
                 weakSelf.mCollectionHC.constant=0;
            }

           
            [weakSelf.mCollection reloadData];
           
        }else
        {
            weakSelf.mCollectionHC.constant=0;
        }
    }];
    
}


#pragma mark - 瀑布流空间的数据源和代理

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    NSArray *array=self.dataArray[section][@"recommend_video"];
    if (![array isEqual:[NSNull null]]) {
         return array.count;
    }else
    {
        return 0;
    }
   
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    
    return self.dataArray.count;

}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    HomeCollectionCell *homeCell=[collectionView dequeueReusableCellWithReuseIdentifier:staticCell forIndexPath:indexPath];
    NSArray *array;
    if (self.dataArray.count>0) {
        array=self.dataArray[indexPath.section][@"recommend_video"];
    }

    
    if (![array isEqual:[NSNull null]]) {
        
        
        NSString *str=[isLogin isHttpHeader:array[indexPath.row][@"attach"][@"attachment"]];
        
         [isLogin setVendorImageUrl:homeCell.bgImg :[isLogin isHttpHeader:str]];
        if ([array[indexPath.row][@"attach"][@"is_image"]integerValue ]==1) {
            homeCell.isPlayBtn.hidden=YES;
            [homeCell removeFromSuperview];
        }else
        {
            homeCell.isPlayBtn.tag=indexPath.row;
            
            [homeCell.isPlayBtn addTarget:self action:@selector(goToPlayVC:) forControlEvents:UIControlEventTouchUpInside];
        
        }
        
    }
    
   
    
    return homeCell;

}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    DLog(@"%@",indexPath);
    
    MoreThanDetailViewController *moreThanDVC=[MoreThanDetailViewController new];
    
    
    [self.navigationController pushViewController:moreThanDVC animated:YES];

}


- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
    return CGSizeMake(__MainScreen_Width, 59);
    
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
{
    
    return CGSizeMake(__MainScreen_Width, 20);
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake((__MainScreen_Width-32)/2,120);

}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath

{
    
    UICollectionReusableView *reusableview = nil;
    
    if (kind == UICollectionElementKindSectionHeader){
        
        HeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];
        
        UILabel *label = headerView.subviews[0];
        
        NSString *title =[isLogin isNull:self.dataArray[indexPath.section][@"title"]];
        label.text=title;
        
        DLog(@"%@",headerView.subviews);
        
        UIButton *button=(UIButton *)[headerView viewWithTag:indexPath.section+5000];
        if (!button) {
            button= [UIButton buttonWithType:UIButtonTypeCustom];
            [button addTarget:self action:@selector(clickMoreThan:) forControlEvents:UIControlEventTouchUpInside];
        }
        
        button.tag=indexPath.section+5000;
        
        
        [button setFont:[UIFont systemFontOfSize:18]];
        
        
        button.frame=CGRectMake(__MainScreen_Width-136,20, 120, 21);
        [button setTitle:@"更多的精彩 >>" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor colorWithHexString:@"#818181"] forState:UIControlStateNormal];
    
        [headerView addSubview:button];
        
      //  CustomButton *button = headerView.subviews[1];
        
      //  button.buttonPath=indexPath;
      //  [button addTarget:self action:@selector(clickMoreThan:) forControlEvents:UIControlEventTouchUpInside];
        
        reusableview = headerView;
        
    }
    
    if (kind == UICollectionElementKindSectionFooter){
        
        FooterReusableView *footerview = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"FooterReusableView" forIndexPath:indexPath];
        reusableview = footerview;
        
    }
    
    return reusableview;
    
    
    
}
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 8, 5, 8);
}


#pragma  mark -私有事件
- (void)goToPlayVC:(CustomButton *)button
{
    DLog(@"播放该页面咯");
    
}


- (void)clickMoreThan:(UIButton *)button
{
    
    MoreThanVedioViewController *moreThanVVC=[MoreThanVedioViewController new];
    
    //获取ID
    
    moreThanVVC.categoryID=self.dataArray[button.tag-5000][@"id"];
    moreThanVVC.title=self.dataArray[button.tag-5000][@"title"];
    
    
    [self.navigationController pushViewController:moreThanVVC animated:YES];
}


//裁剪Navigation上面的选择器
-(void)customNavigation
{

    _segment.tintColor =[UIColor colorWithRed:0.13 green:0.38 blue:0.69 alpha:1];
    _segment.backgroundColor = [UIColor colorWithRed:0.2 green:0.6 blue:0.88 alpha:1];
    _segment.selectedSegmentIndex = 0;
    NSDictionary* selectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:25],
    NSForegroundColorAttributeName: [UIColor whiteColor]};

    [_segment setTitleTextAttributes:selectedTextAttributes forState:UIControlStateSelected];//设置文字属性
    
    NSDictionary* unselectedTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:25],
    NSForegroundColorAttributeName: [UIColor whiteColor]};
    [_segment setTitleTextAttributes:unselectedTextAttributes forState:UIControlStateNormal];
    
    
}


//segmentController的响应事件
-(IBAction)whichPage:(UISegmentedControl *)sender
{
    NSInteger index = sender.selectedSegmentIndex;
    switch (index) {
        case 0:{
           // for (UIView * view in self.view.subviews) {
           //     [view removeFromSuperview];
           // }
            
            /*
            if (_mapView) {
                 [_mapView removeFromSuperview];
            }
             
            */
            
            [_locationManager stopUpdatingLocation];
            _baidumapView .hidden=YES;
             _baidumapView .userInteractionEnabled=NO;
            _MainScrollView.hidden=NO;
            _MainScrollView.userInteractionEnabled=YES;
            
            [self.view insertSubview:_MainScrollView aboveSubview: _baidumapView ];
            
 
            
            
            //[self creatInfoView];
           // [self creatTopScrollerView];
        }
            
            break;
            
        case 1:{
           // for (UIView * view in self.view.subviews) {
              //  [view removeFromSuperview];
           // }
            /*
            if (_MainScrollView) {
                [self.MainScrollView removeFromSuperview];
            }
            */
             _baidumapView .hidden=NO;
             _baidumapView .userInteractionEnabled=YES;
            _MainScrollView.hidden=YES;
            _MainScrollView.userInteractionEnabled=NO;
            [_locationManager startUpdatingLocation ];
            [self.view insertSubview: _baidumapView  aboveSubview:_MainScrollView];
           
            if (! _baidumapView ) {
                [self creatMapView];
                [self location];
            }
            
            
            //地图创建
           
        }
            
            break;
            
            
        default:
            break;
    }
}

#pragma mark  地图
//创建视图
-(void)creatMapView
{
    _baidumapView = [[BMKMapView alloc]initWithFrame:self.MainScrollView.frame];
    [self.view addSubview:_baidumapView];
    _baidumapView.delegate = self;
    

    
//    _baiduLocation = [[BMKLocationService alloc]init];
//    _baiduLocation.delegate = self;
//    _baiduLocation.distanceFilter = 10;
//    //启动定位
//    [_baiduLocation startUserLocationService];
//    CLLocationCoordinate2D coors;
//    coors.latitude = 39.800;
//    coors.longitude = 116.404;
  //  BMKGroundOverlay* ground = [BMKGroundOverlay groundOverlayWithPosition:coors
//                                                                 zoomLevel:13 anchor:CGPointMake(0.0f,0.0f)
//                                                                      icon:[UIImage imageNamed:@"banner图2"]];
  //  BMKGroundOverlay * ground2 = [BMKGroundOverlay groundOverlayWithPosition:coors zoomLevel:11 anchor:CGPointMake(0.0f, 0.0f) icon:[UIImage imageNamed:@"12"]];
  //  [_baidumapView addOverlay:ground];
  //  [_baidumapView addOverlay:ground2];
    
    
//    //添加图片图层覆盖物(第二种:根据指定区域生成)
//    CLLocationCoordinate2D coords[2] = {0};
//    coords[0].latitude = 39.815;
//    coords[0].longitude = 116.404;
//    coords[1].latitude = 39.915;
//    coords[1].longitude = 116.504;
//    BMKCoordinateBounds bound;
//    bound.southWest = coords[0];
//    bound.northEast = coords[1];
//    BMKGroundOverlay* ground2 = [BMKGroundOverlay groundOverlayWithBounds: bound
//                                                                     icon:[UIImage imageNamed:@"banner图2"]];
//    [_baidumapView addOverlay:ground2];
    
    BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
    CLLocationCoordinate2D coor;
    coor.latitude = 39.915;
    coor.longitude = 116.404;
    annotation.coordinate = coor;
    annotation.title = @"这里是北京";
    [_baidumapView addAnnotation:annotation];
    
    
//    // 添加圆形覆盖物
//    CLLocationCoordinate2D coor;
//    coor.latitude = 39.915;
//    coor.longitude = 116.404;
//    BMKCircle * circle = [BMKCircle circleWithCenterCoordinate:coor radius:5000];
//    
//    [_baidumapView addOverlay:circle];
    
    
//    _mapView = [[MKMapView alloc]initWithFrame:self.MainScrollView.frame];
//    
//    [self.view addSubview:_mapView];
//   // [self.hearNavBar bringSubviewToFront:_mapView];
//    //设置代理
//    _mapView.delegate = self;
//    //添加手势
//    _mapView.centerCoordinate =CLLocationCoordinate2DMake(31.05, 121.76);
//    _mapView.userInteractionEnabled=YES;
//
    
//    UILongPressGestureRecognizer * longPressGester = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(onPutPin:)];
//    [_baidumapView addGestureRecognizer:longPressGester];
    
}

//- (BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id<BMKOverlay>)overlay{
//    if ([overlay isKindOfClass:[BMKGroundOverlay class]]){
//        BMKGroundOverlayView* groundView = [[BMKGroundOverlayView alloc] initWithOverlay:overlay] ;
//        return groundView;
//    }
//    return nil;
//}

//- (BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id <BMKOverlay>)overlay{
//    if ([overlay isKindOfClass:[BMKCircle class]]){
//        BMKCircleView * circleView = [[BMKCircleView alloc] initWithOverlay:overlay] ;
//        circleView.fillColor = [[UIColor cyanColor] colorWithAlphaComponent:0.5];
//        circleView.strokeColor = [[UIColor blueColor] colorWithAlphaComponent:0.5];
//        circleView.lineWidth = 10.0;
//        
//        return circleView;
//    }
//    return nil;
//}

- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
{
//    if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
//        BMKPinAnnotationView *newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];
//        newAnnotationView.pinColor = BMKPinAnnotationColorPurple;
//        newAnnotationView.animatesDrop = YES;// 设置该标注点动画显示
//        UIImageView * image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"13"]];
//        newAnnotationView.leftCalloutAccessoryView=image;
//        newAnnotationView.canShowCallout = YES;
//        newAnnotationView.animatesDrop = YES;
//        return newAnnotationView;
//    }
//    return nil;

    
    UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];
   // view.backgroundColor= [UIColor whiteColor];
    UIColor * color = [UIColor clearColor];
    view.backgroundColor = [color colorWithAlphaComponent:0.5];
    UIImageView * imageview = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(view.frame), CGRectGetHeight(view.frame))];
    imageview.image = [UIImage imageNamed:@"图3"];
    [view addSubview:imageview];
    UIButton * label = [[UIButton alloc]initWithFrame:CGRectMake(CGRectGetWidth(view.frame)-40, 0, 40, 40)];
    label.backgroundColor = [UIColor colorWithRed:0.2 green:0.6 blue:0.88 alpha:1];
    [label setTitle:@"4" forState:UIControlStateNormal];
    label.titleLabel.textColor=[UIColor whiteColor];
//    label.text = @"3";
//    label.textColor = [UIColor whiteColor];
 //   label.textAlignment = NSTextAlignmentCenter;
    label.layer.cornerRadius = 20.0f;
    [view addSubview:label];
    //将view换成image
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, view.layer.contentsScale);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    
    BMKPinAnnotationView * anview = (BMKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"pin"];
    if (anview == nil) {
        anview = [(BMKPinAnnotationView *)[BMKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"pin"];
    }
  //   UIImageView * image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"13"]];
   // anview.leftCalloutAccessoryView = image;
    //把大头针改为图片
    anview.image =image;
    
    anview.canShowCallout = YES;
    anview.animatesDrop = YES;
    return anview;
}

////长按手势实现
//-(void)onPutPin:(UILongPressGestureRecognizer *)sender
//{
//    CGPoint  gesterPoint = [sender locationInView:_baidumapView];
//    CLLocationCoordinate2D coor2D = [_baidumapView convertPoint:gesterPoint toCoordinateFromView:_baidumapView];
//    
//    BMKPointAnnotation * pointAnnotion=[[BMKPointAnnotation alloc]init];
//    pointAnnotion.coordinate = coor2D;
//    pointAnnotion.title = @"全是问题";
//    pointAnnotion.subtitle = @"哎";
//    [_baidumapView addAnnotation:pointAnnotion];
//}

//定位

//处理位置坐标更新
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
{
    NSLog(@"didUpdateUserLocation lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);
    
    _baidumapView.showsUserLocation = YES;//显示定位图层
    [_baidumapView updateLocationData:userLocation];
    
    BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
    CLLocationCoordinate2D coor;
    coor.latitude = userLocation.location.coordinate.latitude;
    coor.longitude = userLocation.location.coordinate.longitude;
    annotation.coordinate = coor;
    annotation.title = @"这里是北京";
    [_baidumapView addAnnotation:annotation];
    
}


-(void)location{
//    //创建对象
//    _locationManager = [[CLLocationManager alloc]init];
//    //设置属性
//    _locationManager.desiredAccuracy = kCLLocationAccuracyBest;
//    //设置定位
//    _locationManager.distanceFilter = 10.0;
//    _locationManager.delegate = self;
    //请求用户允许使用定位服务
    
    _baiduLocation = [[BMKLocationService alloc]init];
    _baiduLocation.delegate = self;
    _baiduLocation.distanceFilter = 10;
    //启动定位
    [_baiduLocation startUserLocationService];
    
    CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
    if (status==kCLAuthorizationStatusNotDetermined) {
        [_locationManager requestAlwaysAuthorization];
    }
    else if(status==kCLAuthorizationStatusAuthorizedWhenInUse)
    {
        NSLog(@"前台使用");
    }
    else if (status == kCLAuthorizationStatusDenied)
    {
        NSLog(@"用户已删除");
    }
    else
    {
        NSLog(@"可以一直使用");
    }
    //前台运行时才使用
    [_locationManager requestWhenInUseAuthorization];
    //开始定位
    [_locationManager startUpdatingLocation];
}

//定位后结果的回调
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    for (CLLocation * location in locations) {
        NSLog(@"维度%f 经度%f",location.coordinate.latitude,location.coordinate.longitude);
    }
    
  
    
    //取出数组中第一个经纬度信息
    CLLocation * location = [locations firstObject];
    _mapView.centerCoordinate =location.coordinate;
    //设置地图视图显示该经纬度的位子
    //设置显示区域结构体，中心点，偏移量
    MKCoordinateRegion region= MKCoordinateRegionMake(location.coordinate, MKCoordinateSpanMake(0.00001, 0.01));
    [_mapView setRegion:region animated:YES];
    
    //创建大头针
   
    MKPointAnnotation * point = [[MKPointAnnotation alloc]init];
    MKAnnotationView *annotationView=[[MKAnnotationView alloc] initWithAnnotation:point reuseIdentifier:@"pointView"];
    annotationView.image=[UIImage imageNamed:@"LOGO"];
    annotationView.center=CGPointMake(location.coordinate.latitude, location.coordinate.longitude);
    [_mapView addSubview:annotationView];
    //设置经纬度
    point.coordinate = location.coordinate;
    //设置标题
    [annotationView setEnabled:YES];

    [_mapView selectAnnotation:point animated:YES];
    
    point.title =@"12345";
    point.subtitle = @"6666";
    
    [_mapView addAnnotation:point];
    
   
}




#pragma mark --
#pragma mark -广告轮播

//请求广告图片数据
- (void)getImageArray
{
    [httpRequest getHomeBannerImgComplement:^(NSDictionary *dic) {
        DLog(@"%@",dic);
        if ([dic[@"code"] integerValue]==200) {
            
            NSArray *array=dic[@"data"];
            
            
            if (![array isEqual:[NSNull null]]) {
                if (array.count>0) {
                    for (int i=0; i<array.count; i++) {
                        [self.bannerArray addObject:array[i]];
                    }
                    
                    [self downImg:self.bannerArray];
                }
                
              
                
                
            }
            
        }
        
    }];
    
    

    
}


//广告控件创建 显示
-(void)downImg:(NSArray *)results{
    
    urls = [[NSMutableArray alloc]init];
    
    if (results.count) {
        
        for (int i=0;i<results.count;i++) {
            
            [urls addObject:[isLogin isHttpHeader:[results objectAtIndex:i][@"icon"]]];

        }
        
        [self.bannerView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        //[self.scrollImageView removeFromSuperview];
        
        self.scrollImageView = [BBScrollImageView
                                scrollImageViewWithFrame:CGRectMake(0, 0, __MainScreen_Width, _bannerView.frame.size.height)];
        self.scrollImageView.delegate = self;
        self.scrollImageView.dataSource = self;
        self.scrollImageView.autoPlay = YES;
        
        [self.scrollImageView.pageControl setAlignment:kBBIndicatorAlignmentCenter];
        self.scrollImageView.titleContentView.backgroundColor = [UIColor clearColor];
        self.scrollImageView.showFullImageWhenClick = NO;
        self.scrollImageView.pageControlLimit=100;
        
        // self.scrollImageView.pageControlLimit = 100;
        [self.bannerView addSubview:self.scrollImageView];
        
        
    }else{
        
        [self.bannerView.subviews  makeObjectsPerformSelector:@selector(removeFromSuperview)];
    }
    
}


//这个bannerView只是达到了效果. 真正的使用中需要ADBannerView(官网)或者GADBannerView（ADMob）那个.这个是需要特定的。
//为应用插播广告。第一种是引入 iAD框架  第二种是去ADMob官网注册.然后在上面注册后 插播广告。恩~~类似于国内的第三方平台吧、
#pragma mark -
#pragma mark - BBScrollImageViewDataSource method
- (NSInteger)numberOfImagesInScrollImageView:(BBScrollImageView *)aScrollImageView{
    
    return urls.count;
}

- (NSURL *)scrollImageView:(BBScrollImageView *)aScrollImageView imageUrlAtIndex:(NSInteger)aIndex{
    
    
    
    return [NSURL URLWithString:urls[aIndex]];
    
}



#pragma mark -
#pragma mark - BBScrollImageViewDelegate method
- (void)scrollImageView:(BBScrollImageView *)aScrollImageView didSeletedImageView:(UIImageView *)imageView atIndex:(NSInteger)aIndex{
    
  //跳转对应的页面
    
}



- (void)scrollImageView:(BBScrollImageView *)aScrollImageView didGetImage:(UIImage *)aImage atIndex:(NSInteger)aIndex{
    // NSLog(@"didGetImage:%ld",aIndex);
    
}

- (void)scrollImageView:(BBScrollImageView *)aScrollImageView failedToGetImageAtIndex:(NSInteger)aIndex{
    // NSLog(@"failedToGetImageAtIndex:%ld",aIndex);
}



- (IBAction)goToMyConsoleVC:(id)sender {
    
    
    [self.navigationController pushViewController:[UIViewController getClass:@"MyConsoleViewController"] animated:YES];
}



@end
